﻿using AutoMapper;
using MediatR;
using ProductManagement.Applcation.Command;
using ProductManagement.Domain.ProductsDomain;
using ProductManagement.Infrstructre.Interface;

namespace ProductManagement.Applcation.CommandHanlers
{
    /// <summary>
    /// 消息创建命令处理器
    /// </summary>
    public class MessageCreateCommandHandlers : IRequestHandler<MessageCreateCommand, int>
    {
        protected readonly IMapper mapper;
        protected readonly InterfaceMessageRepository interfaceMessage;

        public MessageCreateCommandHandlers(IMapper mapper, InterfaceMessageRepository interfaceMessage)
        {
            this.mapper = mapper;
            this.interfaceMessage = interfaceMessage;
        }

        public async Task<int> Handle(MessageCreateCommand request, CancellationToken cancellationToken)
        {
            return await interfaceMessage.AddAsync(mapper.Map<Message>(request.dtos));
        }
    }
}
